home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / MarkzScout™ 14-day trial / Layout Scripts / JobTimeLogger.m1s < prev    next >
Encoding:
Text File  |  1999-03-29  |  3.4 KB  |  120 lines  |  [TEXT/ttxt]

  1. proc CalcLogPath
  2.   //
  3.   // Calculate the log path: use the path to the layout (passed through
  4.   // 'it') and append '.log'. This will not work if the layout filename 
  5.   // is longer than 27 characters and does not end on .MSL - try to avoid
  6.   // that, or the log might be appended to your layout file instead.
  7.   //
  8.   logPath = it
  9.   if (upper(right(logPath,4)) = ".MSL") then
  10.     logPath = left(logPath,len(logPath) - 4)
  11.   end if
  12.   logPath = logPath + ".log"
  13. end proc
  14.  
  15. proc OnOpenLayout
  16.   //
  17.   // Create variables for storing job information. These variables
  18.   // need to be created when the layout is opened. Otherwise, they will
  19.   // be removed from memory before the OnEndJob procedure is called.
  20.   // By creating them when the layout opens, they will remain available
  21.   // after the job is processed, and they will keep whatever value was
  22.   // assigned to them while the job was processed.
  23.   //
  24.   logPath = ""
  25.   jobStartTime = 0
  26.   jobClassName = ""
  27.   //
  28.   // Build table of month names. We use a string as the subscript - 
  29.   // month[1] is not the same as month["01"]. Using a string subscript
  30.   // allows us to use MID(somedate,5,2) as the subscript for the month table.
  31.   //
  32.   month["01"] = "Jan"
  33.   month["02"] = "Feb"
  34.   month["03"] = "Mar"
  35.   month["04"] = "Apr"
  36.   month["05"] = "May"
  37.   month["06"] = "Jun"
  38.   month["07"] = "Jul"
  39.   month["08"] = "Aug"
  40.   month["09"] = "Sep"
  41.   month["10"] = "Oct"
  42.   month["11"] = "Nov"
  43.   month["12"] = "Dec"
  44.   call CalcLogPath
  45. end proc
  46.  
  47. proc OnSaveLayout
  48.   call CalcLogPath
  49. end proc
  50.  
  51. proc OnStartJob
  52.   //
  53.   // The job is about to be read by MarkzONE - store the current time
  54.   // (DATE() returns a 14-character string in YYYYMMDDhhmmss format)
  55.   //
  56.   jobStartTime = DATE()
  57. end proc
  58.  
  59. proc OnJobRead
  60.   //
  61.   // The job has been read into memory - store its class name for later
  62.   // reference
  63.   //
  64.   jobClassName = it.class_name
  65. end proc
  66.  
  67. proc OnEndJob
  68.   //
  69.   // Error checking
  70.   //
  71.   if logPath is undefined then
  72.     print "Cannot write log - close and re-open layout first"
  73.     return
  74.   end if
  75.   if logPath = "" then
  76.     print "Cannot write log - save layout first"
  77.     return
  78.   end if
  79.   //
  80.   // Job has been processed and removed from memory. 'it' is the path
  81.   // of the job after processing. Calculate the time elapsed, and
  82.   // write it to the log file. Separate fields by TAB (CHR(9)) characters
  83.   // so it is easy to read the log file into a spreadsheet program.
  84.   // DATE_SECONDS returns a floating point value which corresponds 
  85.   // to the number of seconds between "19700101000000" and the 
  86.   // date string provided. Subtracting the two date values gives
  87.   // us the number of seconds elapsed.
  88.   //
  89.   jobPath = it
  90.   timeTaken = DATE_SECONDS(DATE()) - DATE_SECONDS(jobStartTime)
  91.   //
  92.   // Format the date nicely in now. Use the table of month names
  93.   //
  94.   now = DATE()
  95.   dateNow = 
  96.     MID(now,7,2) + "/" + month[MID(now,5,2)] + "/" + left(now,4)
  97.   timeNow = 
  98.     MID(now,9,2) + ":" + MID(now,11,2) + ":" + RIGHT(now,2)
  99.   //
  100.   // Write to log file in tab text format (Mac) or comma-separated (Win)
  101.   // OS is a system variable.
  102.   //
  103.   if UPPER(OS) = "MAC" then
  104.     write logPath,
  105.       dateNow
  106.        + chr(9) + timeNow
  107.        + chr(9) + jobClassName
  108.        + chr(9) + jobPath 
  109.        + chr(9) + timeTaken 
  110.   else
  111.     write logPath,
  112.       '"' + dateNow + '"'
  113.        + ',"' + timeNow + '"'
  114.        + ',"' + jobClassName + '"'
  115.        + ',"' + jobPath + '"'
  116.        + ',"' + timeTaken + '"'
  117.   end if
  118. end proc
  119.  
  120.